Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--interface and CURLOPT_INTERFACE works different for Ip Address and Interface #13613

Open
pluszeroplus opened this issue May 13, 2024 · 5 comments

Comments

@pluszeroplus
Copy link

I did this

Both of the commands should work
curl -k --interface ens3 https://172.30.0.35
curl -k --interface "172.30.3.145" https://172.30.0.35

I expected the following

only the (1) is able to
ens3 and 172.30.3.145 are the same IP address(I checked by using ifconfig)
This is similar to the issue 11599 and I know that issue was marked as no bug.
I read the source code,and curl uses SO_BINDTODEVICE to bind on the interface. So I think that if I input the IP address, there must be somewhere to tranfers the IP address to the interface. The function may not work properly on some Linux.

curl/libcurl version

7.68.0

operating system

Linux ubuntu

@bagder
Copy link
Member

bagder commented May 13, 2024

I still don't think this is a "bug" per se, but an area for possible improvement. You do ask for a bind to an IP but are saying you want SO_BINDTODEVICE used, so you want curl to find the mapping from IP to device for you and bind the device instead of the IP.

I'm not 100% convinced that is what this option guarantees or says it should do. If you want to bind to the interface device, why not bind to the interface name?

@pluszeroplus
Copy link
Author

if I use the Ip address, which fuction is used to bind the socket on it?

@pluszeroplus
Copy link
Author

I think the reason is that when I use an IP address, curl will use bind to bind the socket to the specified IP. In this case, the operating system just makes sure that the source IP will be the IP address I set. This means that the router rule is not affected.

If I specify the interface, the operating system will make sure that the package will be sent through this interface and ignore the unmatched rules.
my route -n look like this
0.0.0.0 enp4s4(another interface)
0.0.0.0 ens3(the expected one)

@pluszeroplus
Copy link
Author

In the curl documentation, it says CURLOPT_INTERFACE will "set the interface name to use as the outgoing network interface. The name can be an interface name, an IP address, or a hostname". So, I think there should be no difference whether I pass an IP address or an interface name.

@pluszeroplus
Copy link
Author

The bind() system call is frequently misunderstood. It is used to bind to a particular IP address. Only packets destined to that IP address will be received, and any transmitted packets will carry that IP address as their source. bind() does not control anything about the routing of transmitted packets. So for example, if you bound to the IP address of eth0 but you send a packet to a destination where the kernel’s best route goes out eth1, it will happily send the packet out eth1 with the source IP address of eth0. This is perfectly valid for TCP/IP, where packets can traverse unrelated networks on their way to the destination.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants